home *** CD-ROM | disk | FTP | other *** search
- From: mtm4@rsvl.unisys.com (Michael McCormick)
- Message-ID: <Do81tp.H9u@rsvl.unisys.com>
- X-Original-Date: Wed, 13 Mar 1996 19:52:40 GMT
- Path: in2.uu.net!bounce-back
- Date: 13 Mar 96 23:40:59 GMT
- Approved: fjh@cs.mu.oz.au
- Return-Path: <daemon@meeker.UCAR.EDU>
- Newsgroups: comp.std.c++
- Subject: Re: String value of enum
- References: <4i5sf3$89c@hermes.is.co.za>
- Organization: Unisys
- X-Newsreader: Forte Free Agent 1.0.82
- Content-Type: text
- X-Auth: PGPMoose V1.1 PGP comp.std.c++
- iQBFAgUBMUddJ+EDnX0m9pzZAQEVVwF/XFA3mDqWpcigrbyPdU8aWaVW9ZewW9ER
- d0oZMWIjQz84nDPu8WJJUpgqSg7+ScuD
- =s0Hy
-
- "W. Dicks" <wd@isis.co.za> shared the following on 13 Mar 96 07:31:13 GMT:
-
- >The system that I'm working often needs to know the string
- >value of an enum. e.g. enum week{MON=1, ..., SUN} it; it =
- >TUE;
- >Then when this enum is passed as a parameter the function
- >should return the string based on the enum. For instance,
- >weekImage(it) will return "TUE". Is it not possible that such
- >a functionality can be built into enums?
-
- What you are essentially asking for is language support for converting
- a label into a string respresentation of its name. That is a very
- unusual feature to find in any language, since it would require the
- compiler to place the symbolic dictionary in the executable file. I
- don't think there's a snowball's chance of this getting into C++.
-
- Since enum is by definition an integral type, why not assign values to your
- enumerators that can be used as indexes into a string?:
-
- enum week {MON=0,TUE=4,WED=8,THU=12,FRI=16,SAT=20,SUN=24};
- const char * days = "MON\0TUE\0WED\0THU\0FRI\0SAT\0SUN";
-
- char const * weekImage(week day) = days[day];
-
-
-
- ------------------------------------------------------------------
- Mike McCormick // mtm4@rsvl.unisys.com // m.mccormick2@genie.com
- ------------------------------------------------------------------
- Emperor of Cubicle J240-46
- ------------------------------------------------------------------
- All views expressed are my own, not those of my employer.
- ------------------------------------------------------------------
- While you're out surfing the internet...
- I'm back on the beach blowing my little lifeguard whistle.
- ------------------------------------------------------------------
- ---
- [ comp.std.c++ is moderated. To submit articles: try just posting with ]
- [ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
- [ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
- [ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
- [ Comments? mailto:std-c++-request@ncar.ucar.edu ]
-